import { DictData } from '@/types/dictData.model';
import { dictUserStore } from '@/store/modules/dict';
import { to } from 'await-to-js';

export const useDict = (...args: string[]): { [key: string]: DictData[] } => {
  const dictDatas = ref<{ [key: string]: DictData[] }>({});
  return (() => {
    args.forEach(async (dictType) => {
      dictDatas.value[dictType] = [];
      const [err, res] = await to(uni.$u.http.get(`/system/dict/data/type/${dictType}`));
      dictDatas.value[dictType] = res.data.map(
        (p): DictDataOption => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass })
      );
    });
    return dictDatas.value;
  })();
};
